package ru.aptu.billing_server;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

/**
 * Created by IntelliJ IDEA.
 * User: andrey
 * Date: 12/23/11
 * Time: 1:38 AM
 */


/*
 Generating certificate:
 keytool -genkey -keystore mySrvKeystore -keyalg RSA
 */
public class RunServer {

    private static final String CONFIG_FILE = "classes/billing_server.properties";

    public static void main(String[] args) {
        if (args.length != 2) {
            System.out.println("Usage <certificate path> <password>");
            return;
        }

        System.setProperty("javax.net.ssl.keyStore", args[0]);
        System.setProperty("javax.net.ssl.keyStorePassword", args[1]);

        Properties properties = new Properties();
        FileInputStream fileInputStream = null;
        try {
            fileInputStream = new FileInputStream(CONFIG_FILE);
        } catch (FileNotFoundException e) {
            System.err.println("Error: properties file not found!");
        }
        try {
            properties.load(fileInputStream);
        } catch (IOException e) {
            System.err.println("Error reading properties");
        }

        SSLServer sslServer = new AdvancedBillingServer(properties.getProperty("server.address"),
                Integer.parseInt(properties.getProperty("port")));
        sslServer.startServer();
    }
}
